home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / TUT17.ZIP / TUT17.TXT < prev    next >
Text File  |  1995-01-19  |  11KB  |  257 lines

  1.                    ╒═══════════════════════════════╕
  2.                    │         W E L C O M E         │
  3.                    │  To the VGA Trainer Program   │ │
  4.                    │              By               │ │
  5.                    │      DENTHOR of ASPHYXIA      │ │ │
  6.                    ╘═══════════════════════════════╛ │ │
  7.                      ────────────────────────────────┘ │
  8.                        ────────────────────────────────┘
  9.  
  10.                            --==[ PART 17 ]==--
  11.  
  12.  
  13.  
  14. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  15. ■ Introduction
  16.  
  17. Hi there everybody. It's a new year, but the parties are over and it's time
  18. to get coding again!
  19.  
  20. My mailserver died. Various sysadmins decided it was time to upgrade the
  21. OS, and wound up nuking the hard drive :-( ... this means that request-list
  22. is not working at the moment, and I have probably lost lots of mail.
  23.  
  24. denthor@beastie.cs.und.ac.za is still the account to write to, and
  25. hopefully the mailserver will be back up in the near future.
  26.  
  27. There are various C/C++ conversions of my trainer, best of which seem to be
  28. those by Snowman ... he runs through the text files with C++ updates (and
  29. seems to point out my previous mistakes with glee ;-), as well is giving a
  30. fully documented C++ conversion of the source ... very nice stuff.
  31.  
  32. Also, my trainers are being put on a World Wide Web site ... it is still
  33. under construction, but go to http://www.cit.gu.edu.au/~rwong
  34. my site is at http://goth.vironix.co.za/~denthor ... it is currently pretty
  35. awful, anyone want to write a nice one for me? ;)
  36.  
  37. I have just about finished Asphyxia's new game, I will let you all know
  38. when it is completed.
  39.  
  40. Tut 16 dies with large bitmaps ... the way to sort this out is to decrease
  41. the accuracy of the fixed point from 256 to 128 ... then you can have
  42. bitmaps up to 512 pixels wide. I will be putting an updated scale routine
  43. in the gfx4.pas unit.
  44.  
  45. This tutor is on a few demo effects (pixel morphs and static) ... after
  46. this one, I will go on to more theory ... perhaps some more 3d stuff, such
  47. as gourad shading etc. Comments?
  48.  
  49.  
  50. If you would like to contact me, or the team, there are many ways you
  51. can do it : 1) Write a message to Grant Smith/Denthor/Asphyxia in private mail
  52.                   on the ASPHYXIA BBS.
  53.             2) Write to :  Grant Smith
  54.                            P.O.Box 270 Kloof
  55.                            3640
  56.                            Natal
  57.                            South Africa
  58.             3) Call me (Grant Smith) at (031) 73 2129 (leave a message if you
  59.                   call during varsity). Call +27-31-73-2129 if you call
  60.                   from outside South Africa. (It's YOUR phone bill ;-))
  61.             4) Write to denthor@beastie.cs.und.ac.za in E-Mail.
  62.             5) Write to asphyxia@beastie.cs.und.ac.za to get to all of
  63.                us at once.
  64.  
  65. NB : If you are a representative of a company or BBS, and want ASPHYXIA
  66.        to do you a demo, leave mail to me; we can discuss it.
  67. NNB : If you have done/attempted a demo, SEND IT TO ME! We are feeling
  68.         quite lonely and want to meet/help out/exchange code with other demo
  69.         groups. What do you have to lose? Leave a message here and we can work
  70.         out how to transfer it. We really want to hear from you!
  71.  
  72. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  73. ■  Pixel Morphing
  74.  
  75. Have you ever lain down on your back in the grass and looked up at the
  76. cloudy sky? If you have, you have probably seen the clouds move together
  77. and create wonderful shapes ... that cloud plus that cloud together make a
  78. whale ... a ship ... a face etc.
  79.  
  80. We can't quite outdo mother nature, but we can sure give it a shot. The
  81. effect I am going to show you is where various pixels at different starting
  82. points move together and create an overall picture.
  83.  
  84. The theory behind it is simple : Each pixel has bits of data associated
  85. with it, most important of which is as follows :
  86.  
  87. This is my color
  88. This is where I am
  89. This is where I want to be.
  90.  
  91. The pixel, keeping it's color, goes from where it is to where it wants to
  92. be. Our main problem is _how_ it moves from where it is to where it wants
  93. to be. A obvious approach would be to say "If it's destination is above it,
  94. decrement it's y value, if the destination is to the left, decrement it's x
  95. value and so on."
  96.  
  97. This would be bad. The pixel would only ever move at set angles, as you can
  98. see below :
  99.  
  100.                 Dest   O-----------------\
  101.                                            \  <--- Path
  102.                                              \
  103.                                                \
  104.                                                 O Source
  105.  
  106. Doesn't look very nice, does it? The pixels would also take different times
  107. to get to their destination, whereas we want them to reach their points at
  108. the same time, ie :
  109.  
  110.      Dest 1   O-------------------------------O Source 1
  111.      Dest 2   O-----------------O Source 2
  112.  
  113. Pixels 1 and 2 must get to their destinations at the same time for the best
  114. effect. The way this is done by defining the number of frames or "hops"
  115. needed to get from source to destination. For example, we could tell pixel
  116. one it is allowed 64 hops to get to it's destination, and the same for
  117. point 2, and they would both arrive at the same time, even though pixel 2
  118. is closer.
  119.  
  120. The next question, it how do we move the pixels in a straight line? This is
  121. easier then you think...
  122.  
  123. Let us assume that for each pixel, x1,y1 is where it is, and x2,y2 is where
  124. it wants to be.
  125.  
  126.    (x2-x1) = The distance on the X axis between the two points
  127.    (y2-y1) = The distance on the Y axis between the two points
  128.  
  129. If we do the following :
  130.  
  131.   dx := (x2-x1)/64;
  132.  
  133. we come out with a value in dx wich is very useful. If we added dx to x1 64
  134. times, the result would be x2! Let us check...
  135.  
  136.   dx = (x2-x1)/64
  137.   dx*64 = x2-x1         { Multiply both sides by 64 }
  138.   dx*64+x1 = x2         { Add x1 to both sides }
  139.  
  140. This is high school math stuff, and is pretty self explanitory. So what we
  141. have is the x movement for every frame that the pixel has to undergo. We
  142. find the y movement in the same manner.
  143.  
  144.   dy := (y2-y1)/64;
  145.  
  146. So our program is as follows :
  147.  
  148.   Set x1,y1 and x2,y2 values
  149.   dx:= (x2-x1)/64;
  150.   dy:= (y2-y1)/64;
  151.  
  152.   for loop1:=1 to 64 do BEGIN
  153.     putpixel (x1,y1)
  154.     wait;
  155.     clear pixel (x1,y1);
  156.     x1:=x1+dx;
  157.     y1:=y1+dy;
  158.   END;
  159.  
  160. If there was a compiler that could use the above pseudocode, it would move
  161. the pixel from x1,y1 to x2,y2 in 64 steps.
  162.  
  163. So, what we do is set up an array of many pixels with this information, and
  164. move them all at once ... viola, we have pixel morphing! It is usually best
  165. to use a bitmap which defines the color and destination of the pixels, then
  166. randomly scatter them around the screen.
  167.  
  168. Why not use pixel morphing on a base object in 3d? It would be the work of
  169. a moment to add in a Z axis to the above.
  170.  
  171. The sample program uses fixed point math in order to achieve high speeds,
  172. but it is basically the above algorithm.
  173.  
  174.  
  175. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  176. ■  Static
  177.  
  178. A static screen was one of the first effects Asphyxia ever did. We never
  179. actually released it because we couldn't find anywhere it would fit. Maybe
  180. you can.
  181.  
  182. The easiest way to get a sreen of static is to tune your TV into an unused
  183. station ... you even get the cool noise effect too. Those people who build
  184. TV's really know how to code ;-)
  185.  
  186. For us on a PC however, it is not as easy to generate a screen full of
  187. static (unless you desperately need a new monitor)
  188.  
  189. What we do is this :
  190.  
  191. Set colors 1-16 to various shades of grey.
  192. Fill the screen up with random pixels between colors 1 and 16
  193. Rotate the pallette of colors 1 to 16.
  194.  
  195. That's it! You have a screenfull of static! To get two images in one static
  196. screen, all you need to do is fade up/down the specific colors you are
  197. using for static in one of the images.
  198.  
  199. A nice thing about a static screen is that it is just pallette rotations
  200. ... you can do lots of things in the foreground at the same time (such as a
  201. scroller).
  202.  
  203. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  204. ■  In closing
  205.  
  206. Well, that is about it ... as I say, I will be doing more theory stuff in
  207. future, as individual demo effects can be thought up if you know the base
  208. stuff.
  209.  
  210. Note the putpixel in this GFX3.PAS unit ... it is _very_ fast .. but
  211. remember, just calling a procedure eats clock ticks... so imbed putpixels
  212. in your code if you need them. Most of the time a putpixel is not needed
  213. though.
  214.  
  215. PCGPE ][ will be out on the 10th of Feburary. All the new tutors will be on
  216. it (if you aren't reading this from it right now! ;-) ... grab a copy of
  217. it, it is a very useful ting to have handy.
  218.  
  219. I have found out that these tutors have been distributed inside paper
  220. magazines ... please remember that Denthor and Asphyxia retain full
  221. copyright to the series (as mentioned earlier in the series), and if you
  222. want to use a version in a magazine, CONTACT ME FIRST ... I will probably
  223. also modify it/cut out various unneccesary things ... other then that, you
  224. must not alter the files without my permission, or at least leave a copy of
  225. the origional with the update. Maybe I could even start up a nice column
  226. for some magazine or other :)
  227.  
  228. Sorry 'bout that, but it had to be said ...
  229.  
  230. I am writing a column for the Demuan list, a Florida-based electronic
  231. magazine ... pick it up off ftp.eng.ufl.edu ... I have written various
  232. articles, all bordering on quote-like design.
  233.  
  234. There are more BBS's to be added to the list at the end, but I don't have
  235. them here... this tut has taken long enough ;-)
  236.  
  237. Byeeeee....
  238.   - Denthor
  239.  
  240. The following are official ASPHYXIA distribution sites :
  241.  
  242. ╔══════════════════════════╦════════════════╦═════╗
  243. ║BBS Name                  ║Telephone No.   ║Open ║
  244. ╠══════════════════════════╬════════════════╬═════╣
  245. ║ASPHYXIA BBS #1           ║+27-31-765-5312 ║ALL  ║
  246. ║ASPHYXIA BBS #2           ║+27-31-765-6293 ║ALL  ║
  247. ║C-Spam BBS                ║410-531-5886    ║ALL  ║
  248. ║POP!                      ║+27-12-661-1257 ║ALL  ║
  249. ║Soul Asylum               ║+358-0-5055041  ║ALL  ║
  250. ║Wasted Image              ║407-838-4525    ║ALL  ║
  251. ║Reckless Life             ║351-01-716 67 58║ALL  ║
  252. ║Mach 5 BBS                ║+1 319-355-7336 ║ALL  ║
  253. ╚══════════════════════════╩════════════════╩═════╝
  254.  
  255. Leave me mail if you want to become an official Asphyxia BBS
  256. distribution site.
  257.